package view.map;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;

import view.img.ImageLibrary;

import model.map.Direction;
import model.visibility.TileBuilder;
import model.visibility.Visibility;

public class BuildableHexTile extends HexTile implements TileBuilder{
	int x;
	int y;
	Direction currentDirection;
	int energyAmount;
	int foodAmount;
	int oreAmount;
	int numMelee;
	int numRange;
	int numWorkers;
	int numColonists;
	int numExplorers;
	int numRally;
	int numRanged;
	int numVehicles;
	String itemType = "";
	String structureType = "";
	String terrainType = "SAFE_TERRAIN_1";
	Visibility visibility;
	boolean isCursor = false;
	public BuildableHexTile(int _x, int _y){
		super();
		x = _x;
		y = _y;
	}
	public void setCurrentDirection(Direction direction) {
		currentDirection = direction;
	}
	public void setEnergyAmount(int amount) {
		energyAmount = amount;
	}
	public void setFoodAmount(int amount){
		foodAmount = amount;
	}
	public void setItemType(String type) {
		itemType = type;
	}
	public void setNumberColonists(int amount) {
		numColonists = amount;
	}
	public void setNumberExplorers(int amount) {
		numExplorers = amount;
	}
	public void setNumberMelees(int amount) {
		numMelee = amount;
	}
	public void setNumberRallyPoints(int amount) {
		numRally = amount;
	}
	public void setNumberRangeds(int amount) {
		numRanged = amount;
	}
	public void setNumberVehicles(int amount) {
		numVehicles = amount;
	}
	public void setNumberWorkers(int amount) {
		numWorkers = amount;
	}
	public void setOreAmount(int amount) {
		oreAmount = amount;
	}
	public void setStructure(String type) {
		structureType = type;
	}
	public void setTerrain(String terrain) {
		terrainType = terrain;
	}
	public void setVisibility(Visibility visibility) {
		this.visibility = visibility;
	}
	public int getCoordX(){
		return x;
	}
	public int getCoordY(){
		return y;
	}
	public void isCursor(boolean value){
		isCursor = value;
	}
	public void paintComponent(Graphics g){
		Font font = new Font("Default",Font.BOLD,12);
		g.setFont(font);
		g.setColor(Color.black);
		//Paint Terrain Layer
		g.drawImage(ImageLibrary.getImage(terrainType), 0, 0, this);
		//Paint Structure
		if(!structureType.equals("")){
			g.drawImage(ImageLibrary.getImage("_capital"), 47, 40,this);
		}
		//Paint Units and Such
		if(numMelee > 0){
			g.drawImage(ImageLibrary.getImage("_melee"), 30, 6,this);
		}
		if(numExplorers> 0){
			g.drawImage(ImageLibrary.getImage("_explorer"), 57, 6,this);
		}
		if(numColonists > 0){
			g.drawImage(ImageLibrary.getImage("_colonist"), 57, 50,this);
		}
		if(numRanged > 0){
			g.drawImage(ImageLibrary.getImage("_ranged"), 84, 6,this);
		}
		if(numWorkers > 0){
			g.drawImage(ImageLibrary.getImage("_worker"), 57, 72,this);
		}
		if(numVehicles > 0){
			g.drawImage(ImageLibrary.getImage("_vehicle"), 85, 68,this);
		}
		if(numRally > 0){
			g.drawImage(ImageLibrary.getImage("_rally"), 90, 68,this);
		}
		
		//Resources
		g.drawImage(ImageLibrary.getImage("energy"),37,100,this);
		g.drawString(""+energyAmount,40,112);
		g.drawImage(ImageLibrary.getImage("ore"),57,100,this);
		g.drawString(""+oreAmount,60,112);
		g.drawImage(ImageLibrary.getImage("food"),77,100,this);
		g.drawString(""+foodAmount,80,112);
		
    //Paint Item
    if(!itemType.equals("") && !itemType.equals("OBSTACLE"))
    { 
      g.drawImage(ImageLibrary.getImage(itemType), 5, 50,this);
    }
    if( itemType.equals("OBSTACLE") )
    { g.drawImage(ImageLibrary.getImage(itemType), 0, 0,this); }
    //Paint Current
    g.drawImage(ImageLibrary.getImage(currentDirection.toString()), 0, 0,this);
    
  	//Paint Visibility Layer
  	g.drawImage(ImageLibrary.getImage(visibility.toString()), 0, 0,this);
  	if(isCursor){
  	    g.drawImage(ImageLibrary.getImage("cursor"),0,0,this);
  	}
	}
}
